+function($){
  $.fn.setList=function(data,obj,name,btn,page,className){
    var listHtml='',checkboxShow,radioShow;
 // $('.protocol-list').setList(json,'protocol','',btn); //私协无需显示标签
    $.each(data.list,function(i,item){
      btn=='radio' ? radioShow='flex' : radioShow='none';        //正常不显示 flex弹性布局   单选 多选
      btn=='checkbox' ? checkboxShow='flex' : checkboxShow='none';
      if(obj=='business'){  //业务
          if(item.key){ //业务
            var body='<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999 ellipsis" style="vertical-align: inherit;">'+name+item.key+'</font></font></div>'
          }else{
            var body='<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999 ellipsis" style="vertical-align: inherit;">'+name+'</font></font></div>'
          }
          listHtml+='<li >'+
            '<div class="item-link item-content">'+
            '<label class="label-checkbox item-media" id="radioBtn" style="width: 2rem; display:'+radioShow+'"><input onclick="on_radio(this,\'business\')" type="radio" name="radio"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<label class="label-checkbox item-media" id="checkboxBtn" style="width: 2rem; display:'+checkboxShow+'"><input onclick="on_check(this,\'business\')" type="checkbox" name="checkbox"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
              '<a href="/h5/business/detail?id='+item.id+'" style="display: flex; flex:1;width:0;" class="mtb05">'+
              '<div id="itemId" style="display:none;">'+item.id+'</div>'+
              '<div class="item-media">'+
                '<i class="fa fa-user"></i>'+
              '</div>'+
              '<div class="item-inner">'+
                '<div class="item-title-row">'+
                '<div class="item-title"><font style="vertical-align: inherit;"><font class="c3d4145" style="vertical-align: inherit;">'+item.name+'</font></font></div>'+
                '</div>'+body+
              '</div>'+
            '</a>'+
            '</div>'+
          '</li>'
      }else if(obj=='app'){            //应用 
          if(item.url){
            var body='<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999 ellipsis" style="vertical-align: inherit;">'+name+item.url+'</font></font></div>'
          }else{
            var body='<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999 ellipsis" style="vertical-align: inherit;">'+name+'</font></font></div>'
          }
          listHtml+='<li >'+
            '<div class="item-link item-content">'+
            '<label class="label-checkbox item-media" id="radioBtn" style="width: 2rem; display:'+radioShow+'"><input onclick="on_radio(this,\'app\')" type="radio" name="radio"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<label class="label-checkbox item-media" id="checkboxBtn" style="width: 2rem; display:'+checkboxShow+'"><input onclick="on_check(this,\'app\')" type="checkbox" name="checkbox"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
              '<a href="/h5/app/detail?id='+item.id+'" style="display: flex; flex:1;width:0;" class="mtb05">'+
              '<div id="itemId" style="display:none;">'+item.id+'</div>'+
              '<div class="item-media">'+
                '<i class="fa fa-th-large"></i>'+
              '</div>'+
              '<div class="item-inner">'+
                '<div class="item-title-row">'+
                '<div class="item-title"><font style="vertical-align: inherit;"><font class="c3d4145" style="vertical-align: inherit;">'+item.appname+'</font></font></div>'+
                '</div>'+body+
              '</div>'+
            '</a>'+
            '</div>'+
          '</li>'
      }else if(obj=='protocol'){                            //私协
            listHtml+='<li >'+
            '<div class="item-link item-content">'+               
            '<label class="label-checkbox item-media" id="radioBtn" style="width: 2rem; display:'+radioShow+'"><input onclick="on_radio(this,\'protocol\')" type="radio" name="radio"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<label class="label-checkbox item-media" id="checkboxBtn" style="width: 2rem; display:'+checkboxShow+'"><input onclick="on_check(this,\'protocol\')" type="checkbox" name="checkbox"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<a href="/h5/protocol/detail?id='+item.id+'" style="display: flex; flex:1;width:0;" class="mtb05">'+
               '<div id="itemId" style="display:none">'+item.id+'</div>'+
              '<div class="item-media">'+
                '<i class="fa fa-file-o"></i>'+
              '</div>'+
              '<div class="item-inner">'+
                '<div class="item-title-row">'+
                  '<font style="vertical-align: inherit;"><font class="c3d4145" style="vertical-align: inherit;">'+item.name+'</font></font></div>'+
              '</div>'+
            '</a>'+
            '</li>'
      }else{                                        //设备
            listHtml+='<li>'+
            '<div class="item-link item-content">'+               
            '<label class="label-checkbox item-media" id="radioBtn" style="width: 2rem; display:'+radioShow+'"><input onclick="on_radio(this,\'device\')" type="radio" name="radio"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<label class="label-checkbox item-media" id="checkboxBtn" style="width: 2rem; display:'+checkboxShow+'"><input onclick="onDevice_check(this,\'device\')" type="checkbox" name="checkbox"><div class="item-media"><i class="icon icon-form-checkbox"></i></div></label>'+
            '<a href="/h5/device/detail?sn='+item.sn+'" style="display: flex; flex:1;width:0;" class="mtb05">'+
               '<div id="itemId" style="display:none">'+item.userid+'</div>'+
               '<div id="itemSn" style="display:none">'+item.sn+'</div>'+

              '<div class="item-media">'+
                '<i class="fa fa-desktop"></i>'+
              '</div>'+
              '<div class="item-inner">'+
                '<div class="item-title-row device">'+
                   '<div class="item-title"><span><strong>'+item.sn+'</strong></span><br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">设备名称：'+item.name+'</font></font></div>'+
                      '</div>'+
                      '<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999" style="vertical-align: inherit;">创建时间：'+timestampToTime(item.createdate)+'</font></font><br><span class="c999">通信协议：'+checkundefined(item.protocol)+'</span><br><span class="c999">设备业务：'+checkundefined(item.businessname)+'</span></div>'+
              '</div>'+
            '</a>'+
          '</li>'
      }
    })
    if(page==1){
      $(this).replaceWith('<ul class="'+className+'">'+listHtml+'</ul>')
    }else{
      $(this).append(listHtml);
    }
    
  }
$.fn.setStatisticsPhone=function(num,data){
    var statisticsLi='';
    var liWidth=100/num;
    $.each(data,function(i,item){
      statisticsLi += '<li style="width:'+liWidth+'%" id="'+item.id+'" title="'+item.title+'" url="'+item.url+'">'+
                
                '<div class="'+item.color+'">'+
                '<a href="'+item.url+'">'+  
                  '<div class="left-icon">'+
                    '<i class="fa '+item.icon+'"></i>'+
                  '</div>'+
                  '<div class="right-num">'+
                      '<h3>'+item.value+'</h3>'+
                    '<span>'+item.text+'</span>'+
                  '</div>'+
                   '</a>'+
                   '</div>'+
                
              '</li>'
      
    })
    $(this).replaceWith('<ul class="h5statistical-number">'+statisticsLi+'</ul>');
  }
   $.fn.deviceList=function(json){
              var deviceLi='';
                $.each(json.list,function(i,item){
                 deviceLi+='<li>'+
                 '<a href="/h5/device/detail?sn='+item.sn+'" class="item-link item-content">'+
                    '<div class="item-media">'+
                      '<i class="fa fa-desktop"></i>'+
                      "<div class='user-id' style='display:none'>"+item.userid+"</div>"+
                    '</div>'+
                    '<div class="item-inner">'+
                      '<div class="item-title-row">'+
                        '<div class="item-title"><span><strong>'+item.sn+'</strong></span><br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">设备名称：'+item.name+'</font></font></div>'+
                      '</div>'+
                      '<div class="item-subtitle"><font style="vertical-align: inherit;"><font class="c999" style="vertical-align: inherit;">创建时间：'+timestampToTime(item.createdate)+'</font></font><br><span class="c999">通信协议：'+item.protocol+'</span><br><span class="c999">设备业务：'+item.businessname+'</span></div>'+
                    '</div>'+
                  '</a>'+
                '</li>'
                    })
                $(this).append(deviceLi);
                 }

   $.fn.devicedetail=function(item){
    console.log(88888);
            var devicedetailInfo='';
               devicedetailInfo= '<div class="card-content-inner" style="overflow: hidden;">'+
                    '<div class="item-inner devicedetails">'+
                      '<div class="item-title-row devicedetail">'+
                        '<div class="item-title">'+
                            '<p><span>SN：<strong>'+item.sn+'</strong></span></p>'+
                            '<p><span>设备名称:</span><span>'+item.name+'</span></p>'+
                        '</div>'+
                      '</div>'+
                      '<div class="item-subtitle">'+
                           '<p><span>业务名称:</span><span class="device-business">'+checkundefined(item.business)+'</span></p>'+
                           '<p><span>IMSI:</span><span class="device-imsi">'+checkundefined(item.imsi)+'</span></p>'+
                           '<p><span>IMEI:</span><span class="device-imei">'+checkundefined(item.imei)+'</span></p>'+
                           '<p><span>位置:</span><span class="device-location">'+checkundefined(item.location)+'</span></p>'+
                          '<p><span>坐标:</span><span class="device-coordinate">'+checkundefined(item.coordinate)+'</span></p>'+
                          '<p><span>入网方式:</span><span class="device-netway">'+checkundefined(item.netway)+'</span></p>'+
                          '<p><span>设备描述:</span><span class="device-info text-change-line" style="width: 90%;">'+checkundefined(item.info)+'</span></p>'+
                      '</div>'+
                    '</div>'+
                  '</div>'
                $(this).append(devicedetailInfo);
   }

    $.fn.deviceData=function(json){
            var devicedata='';
            var a = '';
             $.each(json.list,function(i,item){
              a=JSON.stringify(item);
             devicedata+= 
               '<div class="card">'+
               '<div class="card-content">'+
              '<div class="item-subtitle devicedata">'+
                        '<a onclick="bbb(this)" class="deviceForbidden">'+
                            '<div style="display:none" id="headdevicedata">'+a+'</div>'+
                            '<p class="createdate"><span>数据接收时间:</span><span >'+item.createdate+'</span></p>'+
                            '<p class="metadata"><span class="metadata">原始数据:</span><span class="metadataitem" >'+item.metadata+'</span></p>'+
                        '</a>'+
                  '</div>'+
                  '</div>'+
                  '</div>'
                  
                })
                $(this).append(devicedata);
   }

    $.fn.deviceConfig=function(json){
            var deviceConfig='';
             $.each(json.list,function(i,item){
             deviceConfig+= 
               '<div class="card">'+
               '<div class="card-content">'+
              '<div class="item-subtitle deviceconfig">'+
                          '<p class="same"><span>配置编号:</span><span >'+item.configid+'</span></p>'+
                          '<p class="same"><span>配置类型:</span><span >'+item.configtype+'</span></p>'+
                          '<p class="same"><span>是否授时:</span><span >'+item.timeservice+'</span></p>'+
                          '<p class="same configdata"><span class="leftconfig">配置数据:</span><span class="rightconfig">'+item.configdata+'</span></p>'+
                          '<p class="same status"><span>状态:</span><span class="statusItem">'+item.status+'</span></p>'+
                          '<p class="same"><span>配置时间:</span><span >'+item.createdate+'</span></p>'+
                  '</div>'+
                  '</div>'+
                  '</div>'
                })
                $(this).append(deviceConfig);
   }

}(jQuery)

 function timestampToTime(timestamp) {
      var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      Y = date.getFullYear() + '-';
      M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      D = date.getDate() + ' ';
      h = (date.getHours() <10 ? '0'+date.getHours() : date.getHours()) + ':';
      m = (date.getMinutes() <10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
      s = (date.getSeconds() <10 ? '0'+date.getSeconds() : date.getSeconds());
      return Y+M+D+h+m+s;
}
function uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 32; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23];
 
    var uuid = s.join("");
    return uuid;
}

